package cs2013;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;


public class MapMain {

	public static void main(String[] args) {
		Map<String, Integer> map=new HashMap<String, Integer>();    
		map.put("Lucy",5 );
		map.put("Lily",4 );
		map.put("Han Meimei",5);
		map.put("Jim",3);
		map.put("Zou Encen",3);
		map.put("Li Wei",5);
		
		String key = "Li Wei";
		Integer value = null;
		if (map.containsKey(key))
		{
			value = map.get(key);
			System.out.println("Use key:" + key + " find value:" + value.intValue());
		}
		else
		{
			System.out.println("Does not contain key:" + key);
		}
		
		key = "Zou Encen";
		if (map.containsKey(key))
		{
			value = map.get(key);
			System.out.println("Use key:" + key + " find value:" + value.intValue());
		}
		else
		{
			System.out.println("Does not contain key:" + key);
			value =  map.get(key);
			System.out.println("Use key:" + key + " find value:" + value + " If map does not contain key, it will return null, be carefull.");
		}
		key = "Tom";
		if (map.containsKey(key))
		{
			value =  map.get(key);
			System.out.println("Use key:" + key + " find value:" + value.intValue());
		}
		else
		{
			System.out.println("Does not contain key:" + key);
		}
		
		Iterator<Entry<String, Integer>> iter = map.entrySet().iterator();
		
		while (iter.hasNext()) {
		Map.Entry<String, Integer> entry =  iter.next();
		Object keys = entry.getKey();
		Object vals = entry.getValue();
		System.out.println("Use iterator to get the second entry is Key :"+ keys+ " Value : " + vals);
		}
        }
        

}
